package com.augmentum.oes.util;

import java.lang.reflect.Field;
import com.augmentum.oes.annotation.Orm.Column;


public final class StringUtil {
    /**
     * Judge that the String is null or not
     */
    public static boolean isEmpty(String str) {
        if (str == null || "".equals(str.trim())) {
            return true;
        } else {
            return false;
        }
    }

/*    public static <T> T getBean(Class<T> clazz, HttpServletRequest request) {
        Map<String, String[]> parameterMap = request.getParameterMap();
        T t = null;
        try {
            t = clazz.newInstance();
        } catch (InstantiationException | IllegalAccessException e1) {
            throw new BaseException(MessageUtils.REFLECT_FAIL);
        }
            Field[] fields = clazz.getDeclaredFields();
            for (int i = 0; i < fields.length; i++) {
                if (parameterMap.get(fields[i].getName()) != null) {
                    fields[i].setAccessible(true);
                    try {
                        fields[i].set(t, parameterMap.get(fields[i].getName())[0].trim());
                    } catch (IllegalArgumentException | IllegalAccessException e) {
                        int number = Integer.parseInt(parameterMap.get(fields[i].getName())[0].trim());

                        try {
                            fields[i].set(t, number);
                        } catch (IllegalArgumentException | IllegalAccessException e1) {
                            e1.printStackTrace();
                        }

                    }
                }
            }
        return t;
    }*/

    public static String getAnnoName(Field field) {
        String annoName;
        String name;
        annoName = field.getAnnotation(Column.class).value();
        if ("".equals(annoName)) {
            name = field.getName();
        } else {
            name = annoName;
        }
        return name;
    }
    public static String firstUpper(String string) {
        String newString = string.substring(0, 1).toUpperCase() + string.substring(1);
        return newString;
    }
    public static String firstLower(String string) {
        String newString = string.substring(0, 1).toLowerCase() + string.substring(1);
        return newString;
    }
    public static String shift(String string) {
        return string.replace("%", "\\%").replace("_", "\\_").trim();
    }
}